﻿using Web.API.IBLL;
using Web.API.IDAL;
using Web.API.Model;
using static System.Runtime.InteropServices.JavaScript.JSType;

namespace Web.API.BLL
{
    public class RoomBLL:RoomIBLL
    {
        public RoomBLL(RoomIDAL<RoomModel> dal) 
        {
            Dal = dal;
        }
        public RoomIDAL<RoomModel> Dal { get;}

        public Task<int> AddRoom(RoomModel room)
        {
           return Dal.AddAsync(room);
        }

        public Task<int> DelRoom(int id)
        {
            var r = Dal.GetAll().FirstOrDefault(x=>x.Id==id);
            return Dal.DeleteAsync(r);
        }

        public List<RoomModel> GetRoom()
        {
           return Dal.GetAll().ToList();
        }

        public Task<int> UpdStart(int id)
        {
          var list=Dal.GetAll().FirstOrDefault(x=>x.Id==id);

            if (list.Start == 1)
            {
                list.Start = 2;
            }
            else
            {
                list.Start = 1;
            }


            return Dal.UpdateAsync(list);
        }
    }
}
